﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LoRel;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CoreTest.KeyAndSchema
{
    [TestClass]
    public class SchemaUnions : SchemaBaseData
    {
        [TestMethod]
        public void SchemaSimple() {

            IEnumerable<Expression> pos_keys = new[] { m_PosSymbol, m_PosTrader };
            IEnumerable<Expression> pos_fields = new[] { m_PosSymbol, m_PosTrader, m_PosQty };

            IEnumerable<Expression> md_keys = new[] { m_MDSymbol };
            IEnumerable<Expression> md_fields = new[] { m_MDSymbol, m_MDPrice };
            
            Schema pos = new Schema( pos_fields, pos_keys );
            Schema md = new Schema( md_fields, md_keys );



            EqualityStatement equality = new EqualityStatement(
                "MY_JOIN", "Symbol", m_PosSymbol, m_MDSymbol, NullTreatment.LEFT);

            Schema join = Join.CreateJoin( "MY_JOIN", NullTreatment.LEFT, pos, md,
                             new List< EqualityStatement >(){equality}, new List< AliasStatement >(), true );
            //Schema join = pos.Union( md );
            //join = join.Union(pos);
            //join = join.Union(md);


            Assert.IsTrue( join[0].Column == "Symbol" );
            Assert.AreNotSame(m_PosSymbol, join[0]);
            Assert.AreSame(m_PosTrader, join[1]);
            Assert.AreSame(m_PosQty, join[2]);
            Assert.AreSame(m_MDPrice, join[3]);

            Console.WriteLine( join );

        }
    }
}
